package org.apache.http.entity.mime.content;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.http.a.a;

public class b extends a {
    private final File a;
    private final String b;

    public b(File file) {
        this(file, org.apache.http.entity.b.n, file != null ? file.getName() : null);
    }

    public b(File file, org.apache.http.entity.b bVar, String str) {
        super(bVar);
        a.a((Object) file, "File");
        this.a = file;
        this.b = str;
    }

    public long getContentLength() {
        return this.a.length();
    }

    public String getFilename() {
        return this.b;
    }

    public String getTransferEncoding() {
        return "binary";
    }

    public void writeTo(OutputStream outputStream) throws IOException {
        a.a((Object) outputStream, "Output stream");
        InputStream fileInputStream = new FileInputStream(this.a);
        try {
            byte[] bArr = new byte[4096];
            while (true) {
                int read = fileInputStream.read(bArr);
                if (read == -1) {
                    break;
                }
                outputStream.write(bArr, 0, read);
            }
            outputStream.flush();
        } finally {
            fileInputStream.close();
        }
    }
}
